<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Zend_View_Helper_LoggedInAs extends Zend_View_Helper_Abstract
{
    public function loggedInAs ()
    {
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $username = $auth->getIdentity()->login;
            $logoutUrl = $this->view->url(array('controller'=>'Auth',
                                                'action'=>'logout'), 
                                                'auth', true);
            $adminArea = $this->view->url(array('controller'=>'Index',
                                                'action'=>'Index'),
                                                'admin',true);
            $infoUtente = $this->view->url(array('controller'=>'Info',
                                                 'action'=>'Index'),
                                                 'info',true);            
            return 'Benvenuto ' . $username 
                 . '. <a href="'.$logoutUrl.'" class="tip">Logout</a>'. " | " 
//                 .'<a href="' . $adminArea .'" class="tip">Admin area</a>'. " | " 
                 .'<a href="'.$infoUtente.'" class="tip">account</a>';
        }

        $request = Zend_Controller_Front::getInstance()->getRequest();
        $controller = $request->getControllerName();
        $action = $request->getActionName();
        if($controller == 'auth' && $action == 'index') {
            return '';
        }
        $loginUrl = $this->view->url(array('controller'=>'auth', 'action'=>'index'),'auth',true);
        return '<a href="'.$loginUrl.'" class="tip">Login</a>';
    }
}
?>